<?php

// No direct access
defined( '_JEXEC' ) or die( 'Restricted access' );

require_once(JPATH_COMPONENT.DS.'models'.DS.'asistencia.php');

/**
 * Controller para la asistencia
 */
class ReghsControllerAsistencia extends ReghsController
{
	/**
	 * constructor (registers additional tasks to methods)
	 * @return void
	 */
	function __construct()
	{
		parent::__construct();

		// Register Extra tasks
		$this->registerTask( 'add'  , 	'edit' );
                $this->registerTask( 'save'  , 	'save' );
                $this->registerTask( 'remove'  , 	'remove' );
	}

	/**
	 * display the edit form
	 * @return void
	 */
	function edit()
	{
		JRequest::setVar( 'view', 'asistencia' );
		JRequest::setVar( 'layout', 'default'  );
		JRequest::setVar('hidemainmenu', 1);

		parent::display();
	}

	/**
	 * save a record (and redirect to main page)
	 * @return void
	 */
	function save()
	{
		$model = $this->getModel('asistencia');

		if ($model->store()) {
			$t = $model->getError();
                        $msg = JText::_( 'Asistencia Guardada!'.$t);
                        $link = 'index.php?option=com_reghs&view=asistencias';
		} else {
			$t = $model->getError();
                        //end($t);
                        //$tmp = current($t);
                        $msg = JText::_( 'Error guardando Asistencia - '.$t );
                        
                        $link = 'index.php?option=com_reghs&view=asistencias';
		}


                //$link = 'index.php?option=com_reghs&view=asistencias';
		//$this->setRedirect($link, $msg);

                //utilizo esta forma porque el redirect normal no me muestra el mensaje
                $this->setRedirect( JRoute::_($link, false), $msg );

	}

	/**
	 * remove record(s)
	 * @return void
	 */
	function remove()
	{
		$model = $this->getModel('asistencia');
		if(!$model->delete()) {
			$msg = JText::_( 'Error: Borrando asistencia' );
		} else {
			$msg = JText::_( 'Asistencia borrada' );
		}

		$this->setRedirect( 'index.php?option=com_reghs&view=asistencias', $msg );
	}

	/**
	 * cancel editing a record
	 * @return void
	 */
	function cancel()
	{
		$msg = JText::_( 'Operacion Cancelada' );
		$this->setRedirect( 'index.php?option=com_reghs&view=asistencias', $msg );
	}

        
}
?>
